<template>
  <div class="conversation" :class="{active: friend.conversationId === data.id}">
    <span class="close-btn iconfont icon-fork" />
    <div class="wrap">
      <div class="avatarBox">
        <el-avatar shape="square" class="portrait margin_r-10" :size="40" :src="data.from.avatar" />
        <span class="unread" v-if="data.unReadCount">{{data.unReadCount > 99 ? 99 : data.unReadCount}}</span>
      </div>
      <div class="content">
        <p class="nickname ellipse-1">
          {{data.from.nickName}}
        </p>
        <div class="message-box">
          <span class="message ellipse-1">
            <span v-if="data.message.type === 1">{{data.message.content}}</span>
            <span v-if="data.message.type === 2">[图片]</span>
          </span>
          <span class="time">{{data.message.createTimeAt}}</span>
        </div>
      </div>
    </div>

  </div>
</template>

<script setup>
import {computed} from "vue"
import {useStore} from "vuex"
const store = useStore()
const friend = computed(() => store.state.conversation.active || {})
const props = defineProps({
  data: {
    type: Object,
    default: () => ({})
  }
})
</script>

<style lang="scss" scoped>

$height: 70px;
$distance: 5px;

.conversation {
  position: relative;
  height: $height;
  padding: 15px 20px;
  cursor: pointer;
  overflow: hidden;
  border-top: 1px solid $borderColor;
  display: flex;
  align-items: center;
  .avatarBox {
    position: relative;
    margin-right: 10px;
    .unread {
      position: absolute;
      bottom: 0px;
      right: 0px;
      width: 15px;
      height: 15px;
      text-align: center;
      line-height: 15px;
      border-radius: 50%;
      font-size: 12px;
      color: white;
      background-color: red;
    }
  }

  .close-btn {
    position: absolute;
    top: $distance;
    right: -20px;
    font-size: 12px;
    color: $darkColor-6;
    transition: .2s;
    &:hover {
      color: $warmColor;
    }
  }
  .wrap {
    display: flex;
    width: 100%;
    .content {
      flex: 1;
      .nickname {
        margin: 0;
        color: #969696;
        font-size: 14px;
        line-height: 21px;
      }
      .message-box {
        padding-top: 3px;
        width: 100%;
        font-size: 12px;
        color: $darkColor-6;
        display: flex;
        justify-content: space-between;
        .message {
          flex: 1;
        }
        .time {
          padding-left: 10px;
        }
      }
    }
  }
  &:hover {
    //background-color: #f0f5ff;
    //.close-btn {
    //  right: $distance;
    //}
  }
}
.active {
  background-color: #f0f5ff;
}
</style>
